import { IPoint } from "@/models/gui";
import { IFn2 } from "@/models/math";
import { getInterpolationFn } from "../hw1/polynomial"

export function getEquidistantFn (points: IPoint[], step: number): { fn: IFn2; start: number, end: number } {
  // t间隔固定, 用多项式插值
  const xPoints = points.map((p, i) => {
    return {
      x: i * step,
      y: p.x,
    };
  });
  const yPoints = points.map((p, i) => {
    return {
      x: i * step,
      y: p.y,
    };
  });
  const fx = getInterpolationFn(xPoints);
  const fy = getInterpolationFn(yPoints);

  const fn = (t) => {
    return {
      x: fx(t),
      y: fy(t),
    };
  };
  return {
    fn,
    start: 0,
    end: (points.length - 1) * step
  }
}